﻿@using WaterRevenueMS.WebUI.Extension.MvcHelper
@using WaterRevenueMS.Domain.ViewModels.Charge.ChargeRecord
@using WaterRevenueMS.Domain.ViewModels.AdminCommon
@model ChargeRecordModel

@{
    ViewBag.Title = ViewBag.CurrentTitle + " - 潍微水务管理系统";

    var editButton = new ButtonModel();
    editButton = ViewBag.Edit;
    var PrintButton = new ButtonModel();
    PrintButton = ViewBag.Edit;
}
@section css{
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.core.css")" rel="Stylesheet" type="text/css"/>  
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.autocomplete.css")" rel="Stylesheet" type="text/css"/> 
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="Stylesheet" type="text/css"/> 
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="Stylesheet" type="text/css"/> 
}

<div id="content-body" class="row-fluid">
    <div class="span22">
        <!--操作 -->
        @Html.Partial("Search", Model.Search)

        <!--列表-->
        @Html.Partial("List")

        <!--新增 & 编辑-->
        @Html.Partial("_FormModal")
    
    </div>
</div>

@section scripts{
    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-zh.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var oTable = null;
        var printId=0;
        $(function () {
            var actionUrl = "@Url.Action("List")?rand=" + Math.random();
            var aoColumns = [
                    { "sName": "SortId", "bSortable": false },
                    { "sName": "UserName", "bSortable": false },
                    { "sName": "Yong_HDZ", "bSortable": false },
                    { "sName": "Yong_HYE", "bSortable": false },
                    { "sName": "Ben_QDS", "bSortable": false },
                     { "sName": "Shang_QDS", "bSortable": false },
                     { "sName": "Ben_QYL", "bSortable": false },
                     { "sName": "He_JYL", "bSortable": false },
                     { "sName": "Ben_CJF", "bSortable": false },
          
                    { "sName": "CreateDT", "bSortable": false },
                    
                     
                    {
                        "sName": "Id",
                        "bSearchable": false,
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            var btnArray = "";

                            @if (editButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-primary btn-normal" title="缴费"  onclick="Edit(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@editButton.Icon"></span></button>'</text>
                            }
                                                     
                            return btnArray;
                        }
                    }
            ];
            //初始化表格
            oTable = InitDatatables($(".data-table"), actionUrl, aoColumns, oTable);
        });

                //查询
        function Search() {
                    var filterdata = $(".search-form").serialize();
                    var actionUrl = "@Url.Action("List")?rand=" + Math.random() + "&" + filterdata;
            SearchRecord(actionUrl, oTable);
        }
         

         //编辑
        function Edit(id) {
            var actionUrl = "@Url.Action("Edit")";
            var param = { Id: id }
             ShowModal(actionUrl, param, "缴费");
             printId=id;

        }

        //保存
        function Save() {
            SavePntModal(oTable);

            bootbox.dialog("你确认要打印？", [{
                "label": "打印",
                "class": "btn-danger",
                "callback": function () {

                    var actionUrl = "ChargeRecord/Payment";
           
                    location.href=actionUrl+"?Id="+printId;
                }
            }, {
                "label": "取消",
                "class": "btn-default"
            }]);
        }


        function SavePntModal(oTable) {
            var actionUrl = $("#modal-content").attr("action");
            var $form = $("#modal-content");

            if (!$form.valid()) {
                return;
            }

            $.ajax({
                type: "POST",
                url: actionUrl,
                data: $form.serialize(),
                success: function (data) {
                    //判断返回值，若为Object类型，即操作成功
                    var result = ((typeof data == 'object') && (data.constructor == Object));
                    if (result) {
                        //bootbox.alert(data.Message);
                        $('#modal-form').modal('hide');
                        ReloadDataTable(oTable);
                    }
                    else {
                        $("#modal-content").html(data);
                    }
                }
            });
            }
        function Payment(id){
            var actionUrl="@Url.Action("Payment")";
            var param={Id:id};
            location.href=actionUrl+"?Id="+id;
        }
    </script>
}

